package com.world.business.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.world.business.user.domain.UserEquipment;
import com.world.business.user.domain.query.*;
import com.world.business.user.domain.vo.UserEquipmentVO;
import com.world.business.user.service.IUserEquipmentService;
import com.world.common.controller.BaseController;
import com.world.common.domain.PageResult;
import com.world.common.domain.ResponseData;
import com.world.common.domain.SuccessResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户装备 前端控制器
 * </p>
 *
 * @author 邓驴
 * @since 2023-07-27
 */
@Api(tags = "用户装备")
@RestController
@RequestMapping("/user/equipment")
public class UserEquipmentController extends BaseController<UserEquipment> {

    @Resource
    private IUserEquipmentService userEquipmentService;

    @ApiOperation("分页")
    @GetMapping("/page")
    public ResponseData<PageResult<UserEquipmentVO>> page(UserEquipmentPageRequest request) {
        IPage<UserEquipmentVO> page = userEquipmentService.getPage(startPage(request), request);
        return new SuccessResponseData<>(getPageResult(page));
    }

    @ApiOperation("新增")
    @PostMapping("")
    public ResponseData<Long> add(@Validated @RequestBody UserEquipmentAddRequest request) {
        return new SuccessResponseData<>(userEquipmentService.add(request));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseData<Void> delete(@PathVariable("id") Long id) {
        userEquipmentService.delete(id);
        return new SuccessResponseData<>();
    }

    @ApiOperation("用户装备数量变更")
    @PutMapping("/numChangeById")
    public ResponseData<Void> numChangeById(@Validated @RequestBody UserEquipmentNumChangeByIdRequest request) {
        userEquipmentService.numChangeById(request);
        return new SuccessResponseData<>();
    }

    @ApiOperation("用户装备数量变更")
    @PutMapping("/numChange")
    public ResponseData<Void> numChange(@Validated @RequestBody UserEquipmentNumChangeRequest request) {
        userEquipmentService.numChange(request);
        return new SuccessResponseData<>();
    }

    @ApiOperation("装备损耗")
    @PutMapping("loss")
    public ResponseData<Void> equipmentLoss(@Validated @RequestBody UserEquipmentLossRequest request) {
        userEquipmentService.equipmentLoss(request);
        return new SuccessResponseData<>();
    }

    @ApiOperation("用户装备详情")
    @GetMapping("/{userId}")
    public ResponseData<List<UserEquipmentVO>> get(@PathVariable("userId") Long userId) {
        return new SuccessResponseData<>(userEquipmentService.get(userId));
    }


}
